// pages/shop/shop_info/shop_info.js

import * as API_Shop from '../../../api/shop.js'
import { Foundation } from '../../../ui-utils/index.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //轮播图设置
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 2000,
    duration: 500,
    //店铺信息
    shopInfo: {},
    silde: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    // options.shop_id
    API_Shop.getShopBaseInfo(options.shop_id).then(response => {
      let time = Foundation.unixToDate(response.shop_createtime, 'yyyy-MM-dd');
      this.setData({ shopInfo: response })
      this.setData({ 'shopInfo.shop_createtime': time })
      this.setData({ 'shopInfo.photo_album': response.photo_album.split(",") })
    });
    API_Shop.getShopSildes(options.shop_id).then(res => {
      this.setData({ silde: res })
    })
  },
  previewImg(e) {
    let index = e.currentTarget.dataset['index']
    let that = this;
    wx.previewImage({
      current: that.data.shopInfo.photo_album[index],
      urls: that.data.shopInfo.photo_album
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})